#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char const* argv[])
{
    int n, buf_len, i, j, ans;
    char buf[10000];

    scanf("%d", &n);

    while (n--) {
        scanf("%s", buf);
        buf_len = strlen(buf);

        for (i = 0; i < buf_len-1; i++) {
            j = i+1;
            ans = 1;
            while (buf[j] == buf[i] && j < buf_len) {
                j++; ans++;
            }

            if (ans > 1) {
                printf("%d", ans);
                i = j-1;
            }
            printf("%c", buf[i]);
        }

        printf("\n");
    }

    return 0;
}
